//
//  GlobalConfig.swift
//  Employee
//
//  Created by swordjoy on 2017/3/13.
//  Copyright © 2017年 remotevillage. All rights reserved.
//

import Foundation
import Moya
import UIKit
import AssetsLibrary
import Photos

public struct GlobalConfig {
    
    
    static var DEBUG: Bool {
        #if DEBUG
        return true
        #else
        return false
        #endif
    }
    private static var serviceType: Bool {
        if SJToolkitConfig.serviceType {
            return true
        } else {
            return DEBUG
        }
    }
    

    static var BASE_URL: String {
        if serviceType {
            return "http://shiwaixiangcun.cn"
        }
        return "http://hxteb.com"
    }
    static var BASE_OUT_URL: String {
        if serviceType {
            return "http://sc.shiwaixiangcun.cn"
        }
        return "http://sc.hxteb.com"
    }
    static var JSPush_Key: String {
        return "aae6cffc31fa82084f7e0e4e"
    }
    static let privateKey = "ea789c208f1e4c9fa37dde31828ced1d"
    
  /// 请求开始加入这个字典,请求完成移除
  static var requestCache = Dictionary<String, Cancellable>()
  
  static var userDefaults = UserDefaults.standard
  static var notificationCenter = NotificationCenter.default
  
//  static var reachability = Reachability
  
  static let system12Font = UIFont.systemFont(ofSize: 12)
  static let system14Font = UIFont.systemFont(ofSize: 14)
  static let system15Font = UIFont.systemFont(ofSize: 15)
  static let system16Font = UIFont.systemFont(ofSize: 16)
  static let system17Font = UIFont.systemFont(ofSize: 17)
  static let system18Font = UIFont.systemFont(ofSize: 18)
  static let system22Font = UIFont.systemFont(ofSize: 22)
  static let bold20Font = UIFont.boldSystemFont(ofSize: 20)
  static let blod15Font = UIFont.boldSystemFont(ofSize: 15)
  
  static let BGWhiteColor = UIColor(red: 245.0 / 255.0, green: 245.0 / 255.0, blue: 245.0 / 255.0, alpha: 1.0)
  static let BGSkyBlueColor = UIColor(red: 45.0 / 255.0, green: 150 / 255.0, blue: 241 / 255.0, alpha: 1.0)
  static let BGLightBlueColor = GlobalConfig.BGSkyBlueColor.withAlphaComponent(0.4)
  static let TextLightColor = UIColor(red: 152.0 / 255.0, green: 157.0 / 255.0, blue: 164.0 / 255.0, alpha: 1.0)
  static let TextDeepColor = UIColor(red: 50.0 / 255.0, green: 60.0 / 255.0, blue: 73.0 / 255.0, alpha: 1.0)
  static let Text08DeepColor = GlobalConfig.TextDeepColor.withAlphaComponent(0.8)
  static let BGLightGreyColor = GlobalConfig.TextDeepColor.withAlphaComponent(0.2)
  static let GrapeFruitColor = UIColor(red: 251.0 / 255.0, green: 95.0 / 255.0, blue: 95.0 / 255.0, alpha: 1.0)
  static let PaleTealColor = UIColor(red: 128.0 / 255.0, green: 203.0 / 255.0, blue: 154.0 / 255.0, alpha: 1.0)
    static let LightBackgroundColor = UIColor(red: 45.0 / 255.0, green: 50.0 / 255.0, blue: 48.0 / 255.0, alpha: 0.15)
    static let MainColor = UIColor(red: 28 / 255.0, green: 204 / 255.0, blue: 140 / 255.0, alpha: 1.0)
    
  
  
  static let BGSkyBlueImage = UIImage.getLinerGradientImage(with: UIColor.hex("#2D96F1"), endColor: UIColor.hex("#04BEFE"), size: CGSize(width: UIScreen.width, height: UIScreen.navBarHeight))
  static let BGWhiteImage = UIImage.getImage(with: UIColor.white, size: CGSizeMake(1, 1))
  
  static let NavBarRootTitleAttributes = [NSForegroundColorAttributeName : UIColor.white, NSFontAttributeName : UIFont.boldSystemFont(ofSize: 17)]
  static let NavBarStackTitleAttributes = [NSForegroundColorAttributeName : TextDeepColor, NSFontAttributeName : UIFont.boldSystemFont(ofSize: 17)]
  
  static let DefaultHeadIconImage = UIImage(named: "Default_HeadIcon")
  static let PlaceholderImage = UIImage(named: "seize-pic")
  
  
  
  // 扫描二维码
  static func qrCodeController(resultClosure: @escaping (String) -> () ) -> LBXScanViewController {
    
    var style = LBXScanViewStyle()
    style.centerUpOffset = 44;
    style.photoframeAngleStyle = LBXScanViewPhotoframeAngleStyle.Inner;
    style.photoframeLineW = 3;
    style.photoframeAngleW = 18;
    style.photoframeAngleH = 18;
    style.isNeedShowRetangle = false;
    
    style.anmiationStyle = LBXScanViewAnimationStyle.LineMove;
    
    //qq里面的线条图片
    style.animationImage = UIImage(named: "qrcode_scan_light_green")
    
    let vc = LBXScanViewController();
    vc.scanStyle = style
    
    vc.getScanResult = { result in
      
     resultClosure(result)
    }
    
    return vc
  }
  
  static func isAuthorizationVideo() -> Bool {
    let state = AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo)
    
    if state == .authorized {
      
      return true
      
    } else if state == .notDetermined {
      
      return true
      
    } else {
      
      let alertController = UIAlertController(title: "无法使用相机", message:"请在iPhone的\"设置-隐私-相机\"中允许访问相机", preferredStyle: .alert)
      let alertAction = UIAlertAction(title: "取消", style: .default, handler: nil)
      let setAction = UIAlertAction(title: "设置", style: .default, handler: { (action) in
        
        SJApp.openSet()
        
      })
      alertController.addAction(alertAction)
      alertController.addAction(setAction)
      SJApp.keyWindow.rootViewController?.present(alertController, animated: true, completion: nil)
      return false
      
    }
    
  }
  
    static func baiduStatisticsPageViewStart(_ name: String) {
        #if RELEASE
//            BaiduMobStat.default().pageviewStart(withName: name)
        #endif
    }
    
    static func baiduStatisticsPageViewEnd(_ name: String) {
        #if RELEASE
//            BaiduMobStat.default().pageviewEnd(withName: name)
        #endif
    }
    

}

